home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / utils / msgval / msgval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.4 KB  |  113 lines

  1. #include <exec/exec.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. char msgbase[200];
  6.  
  7. struct MailHeader {
  8.     char    Status[1];
  9.     long    MsgNumb;
  10.     char    ToName[31],
  11.         FromName[31],
  12.         Subject[31];
  13.     long    MsgDate,
  14.         Recv;
  15.     char Pad;
  16.     };
  17. void sr(char *s);
  18.  
  19. main(int argc,char *argv[])
  20. {
  21.   int i;
  22.   FILE *fi;
  23.   int lost=0;
  24.   int remit=0;
  25.   ULONG Position;
  26.   struct MailHeader t;
  27.   char headername[200];
  28.   char filename[200];
  29.   if(argc<2)
  30.   {
  31.     printf("\n");
  32.     printf(" .------------------------------------------------------.\n");
  33.     printf(" | Ami-Express MsgVal Version 1.1 Written by ByteMaster |\n");
  34.     printf(" |       /X Development Team - The Silent Achievers     |\n");
  35.     printf(" `------------------------------------------------------'\n");
  36.     printf("\n");
  37.     printf("usage: MsgVal <msgbase directory> [Delete]\n");
  38.     printf("   ie: MsgVal BBS:PD/msgbase\n");
  39.     printf("   ie: MsgVal BBS:PD/msgbase Delete\n");
  40.     printf("\n");
  41.     exit(0);
  42.   }
  43.   if(argc==3) remit=1;
  44.  
  45.   printf("\n");
  46.   printf(" .------------------------------------------------------.\n");
  47.   printf(" | Ami-Express MsgVal Version 1.1 Written by ByteMaster |\n");
  48.   printf(" |      /X Development Team - The Silent Achievers      |\n");
  49.   printf(" `------------------------------------------------------'\n");
  50.   printf("\n");
  51.  
  52.   strcpy(msgbase,argv[1]);
  53.   
  54.   
  55.   sr(msgbase);
  56.   
  57.   i=strlen(msgbase)-1;
  58.   if(msgbase[i]!=':' && msgbase[i]!='/') strcat(msgbase,"/");
  59.   
  60.   sprintf(headername,"%sheaderfile",msgbase);
  61.   
  62.   Position=0L;
  63.   
  64.   fi=fopen(headername,"r+b");
  65.   
  66.   if(fi==NULL)
  67.   {
  68.     printf("\n");
  69.     printf("Error, can't locate msgbase\n");
  70.     printf("\n");
  71.     exit(0);
  72.   }
  73.   
  74.   printf("\n");
  75.   printf("\n");
  76.   printf("Scanning Message Base for lost messages\n\n");
  77.   
  78.   while(fread((APTR)&t,sizeof(struct MailHeader),1,fi)!=NULL)
  79.   {
  80.   
  81.     if(t.Status[0]!='D')
  82.     {
  83.       sprintf(filename,"%s%d",msgbase,t.MsgNumb);
  84.       if(access(filename,00))
  85.       {
  86.         printf("Error, Lost Msg number # %ld\n",t.MsgNumb);
  87.         t.Status[0]='D';
  88.         if(remit) { fseek(fi,Position,0L); fwrite((APTR)&t,sizeof(struct MailHeader),1,fi); 
  89.                     fseek(fi,Position,0L); }
  90.         lost +=1;
  91.       }
  92.     
  93.     }
  94.     Position=ftell(fi);
  95.   }
  96.   fclose(fi);
  97.   if(lost)printf("Total Lost messages = %d\n",lost);
  98.   else
  99.   printf("MsgVal reports no lost messages\n\n");
  100.   exit(0);
  101. }
  102.  
  103. void sr(char *s)
  104. {
  105.   register int i;
  106.   i=strlen(s)-1;
  107.   while(i>-1)
  108.   {
  109.     if(*(s+i)<=32) *(s+i)='\0'; else break;
  110.     i--;
  111.   }
  112. }
  113.